import json
import time
from reptile.workproject import WorkProject


class ProxyScrape(WorkProject):

	def work(self):
		super().work()
		proxy_ip_pool = json.loads(
			self.scraper.send_request(url = "https://api.proxyscrape.com/proxytable.php?nf=true&country=all"))
		anonymity = {2: True, 3: False}
		for protocol in proxy_ip_pool:
			for ip_port, ip_inf in proxy_ip_pool[protocol].items():
				self.data.append({"protocol": protocol.lower(), "ip_port": ip_port, "country": ip_inf['country'],
								  "anonymity": anonymity[ip_inf['anonymity']]})
